#!/bin/sh
# this is a helper script
# called by build.sh inside /aufs_sources

[ "$1" ] || exit
kver=$1
kseries=$(echo $kver | cut -f1-2 -d '.')

if [ "$kseries" = "3.4" ] ; then
	if vercmp $kver ge 3.4.112 ; then
		# In patch patch-3.4.112, fs/file_table.c was severely altered
		# (http://ftp.ntu.edu.tw/linux/kernel/v3.x/patch-3.4.112.xz)
		# Could not insert this line:
		#	+EXPORT_SYMBOL(file_sb_list_del);
		# as 'file_sb_list_del()' was deleted. so
		patch -N -p1 < ../patches/aufs_sources/k3.4.112.patch
	fi
fi

if [ "$kseries" = "3.16" ] ; then
	if vercmp $kver ge 3.16.35 ; then
		# error: ‘struct dentry’ has no member named ‘d_alias’
		# error: ‘union <anonymous>’ has no member named ‘d_child’
		# - https://github.com/torvalds/linux/commit/946e51f2bf37f1656916eb75bd0742ba33983c28
		patch -N -p1 < ../patches/aufs_sources/k3.16.35.patch
	fi
fi

if [ "$kseries" = "3.2" ] ; then
	if vercmp $kver ge 3.2.66 ; then
		# error: ‘struct dentry’ has no member named ‘d_alias’
		# error: ‘union <anonymous>’ has no member named ‘d_child’
		# - https://github.com/sfjro/aufs3-linux/commit/30d345d
		patch -N -p1 < ../patches/aufs_sources/k3.2.66.patch
	fi
fi

### END ###
